from typing import *


class BinaryIndexedTree():

    # 参数均为未调整原始位置，方法内调整

    def __init__(self, ceil: int) -> None:
        self.ceil = ceil + 10
        self.bits = [0] * self.ceil  # 树状和，右移1位坐标
        self.nums = [0] * ceil  # 原始数字，原始坐标

    def initArray(self, nums: List[int]):
        # 将数组初始化到树状数组上
        for i, v in enumerate(nums):
            self.add(i, v)
        self.nums[i] = nums[i]

    def lowbit(self, index: int) -> int:
        return index & -index

    def add(self, index: int, value: int) -> None:
        # index 增加 value
        self.nums[index] += value  # 原始数字增加
        # 调整坐标后 bits增加
        index += 1
        while index < self.ceil:
            self.bits[index] += value
            index += self.lowbit(index)

    def query(self, index: int) -> int:
        # 查询[0,index]的和
        index += 1
        ret = 0
        while index > 0:
            ret += self.bits[index]
            index -= self.lowbit(index)
        return ret

    def valueAt(self, index: int) -> int:
        # 查询index处值，self.nums[index]
        # return self.nums[index]
        return self.query(index) - self.query(index - 1)

    def update(self, index: int, value: int) -> None:
        # 更新index数值为value
        # val = self.valueAt(index)
        diff = value - self.nums[index]  # 变更差值
        self.add(index, diff)

    def sumRange(self, left: int, right: int) -> int:  # 原始坐标
        # 区间[left,right]和
        return self.query(right) - self.query(left - 1)


class NumArray:

    def __init__(self, nums: List[int]):
        self.bid = BinaryIndexedTree(len(nums))
        self.bid.initArray(nums)

    def update(self, index: int, val: int) -> None:
        self.bid.update(index, val)

    def sumRange(self, left: int, right: int) -> int:
        return self.bid.sumRange(left, right)


op = [
    "NumArray", "update", "update", "update", "sumRange", "update", "sumRange",
    "update", "sumRange", "sumRange", "update"
]
params = [[[7, 2, 7, 2, 0]], [4, 6], [0, 2], [0, 9], [4, 4], [3, 8], [0, 4],
          [4, 1], [0, 3], [0, 4], [0, 4]]

na = NumArray(params[0][0])

do = zip(op, params)

for op, param in zip(op, params):
    if op == 'NumArray':
        na = NumArray(params[0][0])
    elif op == 'update':
        na.update(*tuple(param))
    else:
        print(na.sumRange(*tuple(param)))
